package com.example.demo.topic.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.topic.entity.TCollectRecord;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.util.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.example.demo.topic.service.ITCommentLikesService;
import com.example.demo.topic.entity.TCommentLikes;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 评论点赞表; 前端控制器
 * </p>
 *
 * @author tao
 * @since 2024-10-29
 */
@RestController
@RequestMapping("/tCommentLikes")
    public class TCommentLikesController {

    @Autowired
    private ITCommentLikesService tCommentLikesService;

    /**
    * 获取相关列表
     * @param current
     * @param size
     * @return
    */
    @GetMapping("/getTCommentLikesList")
    public Result<?> getTCommentLikesList(@RequestParam(value = "current", required = false, defaultValue = "1")Integer current,
                                            @RequestParam(value = "size", required = false, defaultValue = "10")Integer size,
                                            TCommentLikes tCommentLikes){

        Page<TCommentLikes> page = new Page<>(current,size);
        QueryWrapper<TCommentLikes> queryWrapper=new QueryWrapper<>(tCommentLikes);
        queryWrapper.orderByDesc("id");
        return Result.ok(tCommentLikesService.page(page,queryWrapper));
    }

    /**
         * 根据ID查询信息
         */
    @GetMapping("/getTCommentLikesById")
    public Result<?> getTCommentLikesById(Integer id){
        return Result.ok(tCommentLikesService.getById(id));
    }

    /**
         * 修改
         */
    @PutMapping("/updateTCommentLikes")
    @Transactional
    public Result<?> updateTCommentLikes(@RequestBody TCommentLikes tCommentLikes){
        return Result.ok(tCommentLikesService.updateById(tCommentLikes));
    }

    /**
         * 新增
         */
    @PostMapping("/addTCommentLikes")
    public Result<?> addTCommentLikes(@RequestBody TCommentLikes tCommentLikes){
        return Result.ok(tCommentLikesService.save(tCommentLikes));
    }

    /**
         * 删除
         */
    @DeleteMapping("/deleteTCommentLikesById")
    @Transactional
    public Result<?> deleteTCommentLikes(Integer id){
        return Result.ok(tCommentLikesService.removeById(id));
    }

    /**
     * 移动端取消收藏
     */
    @DeleteMapping("/cancelCommentLikes")
    @Operation(summary = "移动端取消评论点赞", description = "移动端取消评论点赞")
    @Transactional
    public Result<?> cancelCollect(@RequestBody TCommentLikes tCommentLikes){
        QueryWrapper<TCommentLikes> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uid",tCommentLikes.getUid());
        queryWrapper.eq("cid",tCommentLikes.getCid());
        return Result.ok(tCommentLikesService.remove(queryWrapper));
    }

}

